//引入axios实例
import request from "@/utils/request"

//基础销售属性的每一项的类型
export interface BaseSaleAttrItemType {
    id?: number,
    name: string
}

//基础销售属性的的类型
export type BaseSaleAttrListType = BaseSaleAttrItemType[]

//根据supid请求的图片列表的每一项的类型
export interface SpuImageItemType {
    id?: number,
    imgName: string,
    imgUrl: string,
    spuId?: number,
    name?: string,
    url?: string,
    response?: any,
    isDefault?: string
}

//根据supid请求的图片列表的完整的类型
export type SpuImageListType = SpuImageItemType[]

//根据supid请求的销售属性值列表的每一项类型
export interface SpuSaleAttrValueItemType {
    baseSaleAttrId?: number,
    id?: number,
    isChecked: string,
    saleAttrName: string,
    saleAttrValueName: string,
    spuId?: number
}

//根据supid请求的销售属性值列表的类型
export type SpuSaleAttrValueListType = SpuSaleAttrValueItemType[]

//根据spuid请求的销售属性列表的每一项的类型
export interface SpuSaleAttrItemType {
    baseSaleAttrId?: number,
    id?: number,
    saleAttrName: string,
    spuId?: number,
    spuSaleAttrValueList: SpuSaleAttrValueListType,
    isEdit?: boolean;
    inputValue?: string;
    SaleIdValueId?: string
}

//根据spuid请求的销售属性列表的类型
export type SpuSaleAttrListType = SpuSaleAttrItemType[]

//一个完整的sup的类型
export interface supInfoType {
    category3Id?: number,
    description: string,
    id?: number,
    tmId?: number | null,
    spuName: string,
    spuImageList: SpuImageListType | null,
    spuSaleAttrList: SpuSaleAttrListType | null,
}


//sup分页列表请求的返回值类型
export interface SpuPageListType {
    total: number,
    size: number,
    current: number,
    searchCount: boolean,
    pages: number
    records: supInfoType[]
}


//1.spu所有的销售属性列表请求
export const requestBaseSaleAttrList = () => {
    return request.get<any, BaseSaleAttrListType>(`/admin/product/baseSaleAttrList`)
}

//2.删除spu
export const requestDeleteSpu = (spuId: number) => {
    return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`)
}

//3.新增sup
export const requestSaveSpuInfo = (spuInfo: supInfoType) => {
    return request.post<any, null>(`/admin/product/saveSpuInfo` , spuInfo)
}

//4.修改sup
export const requestUpdateSpuInfo = (spuInfo: supInfoType) => {
    return request.post<any , null>(`/admin/product/updateSpuInfo` , spuInfo)
}

//5.sup分页列表请求
export const requestSpuPage = (page: number , limit: number , category3Id: number) => {
    return request.get<any , SpuPageListType>(`/admin/product/${page}/${limit}/?category3Id=${category3Id}`)
}

//6.根据spuId请求销售属性列表
export const requestSpuSaleAttrList = (spuId: number) => {
    return request.get<any , SpuSaleAttrListType>(`/admin/product/spuSaleAttrList/${spuId}`)
}

//7.根据supId请求图片列表
export const requestSpuImageList = (spuId: number) => {
    return request.get<any , SpuImageListType>(`/admin/product/spuImageList/${spuId}`)
}

